package com.ljf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljf.annotation.HasPermission;
import com.ljf.dto.ExchangePointPageDto;
import com.ljf.entity.ExchangePointProducts;
import com.ljf.entity.PointProducts;
import com.ljf.service.ExchangePointProductService;
import com.ljf.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/sale_management/exchange_point_products_records")
public class ExchangePointProductsRecordsController {

    @Autowired
    private ExchangePointProductService exchangePointProductService;

    @GetMapping("/queryPointProductBymemberId")
    public Result queryPointProductBymemberid(Long memberId){
        List<Map<String, Object>> list = exchangePointProductService.queryPointProductBymemberId(memberId);
        return Result.success(list);
    }
    @GetMapping("/queryOptionsMember")
    public Result queryOptionsMember() {
        List<Map<String, Object>> list = exchangePointProductService.queryOptionsMember();
        return Result.success(list);
    }
    @GetMapping("/queryOptionsPointProducts")
    public Result queryOptionsPointProducts() {
        List<Map<String, Object>> list = exchangePointProductService.queryOptionsPointProducts();
        return Result.success(list);
    }
    @GetMapping("/queryPointProductByGoodsId")
    public Result queryPointProductByGoodsId(Long goodsId) {
        PointProducts pointProducts = exchangePointProductService.queryPointProductByGoodsId(goodsId);
        return Result.success(pointProducts);
    }
    @PostMapping("/saveExchangePointProductRecords")
    public Result saveExchangePointProductRecords(ExchangePointProducts exchangePointProducts, HttpServletRequest request) {
        exchangePointProductService.saveExchangePointProductRecords(exchangePointProducts, (String) request.getHeader("token"));
        return Result.success();
    }

    @HasPermission("sale_management:exchange_point_products_records:list")
    @PostMapping("/queryPageByQoExchangePointProducts")
    public Result queryPageByQoExchangePointProducts(ExchangePointPageDto dto) {
        Page<ExchangePointProducts> page = exchangePointProductService.queryPageByQoExchangePointProducts(dto);

        return Result.success(page);
    }
    @GetMapping("/queryOptionsMemberPhone")
    public Result queryOptionsMemberPhone() {
        List<Map<String, Object>> list = exchangePointProductService.queryOptionsMemberPhone();
        return Result.success(list);
    }

    @GetMapping("/delExchangePointProducts")
    public Result delExchangePointProducts(String cn) {
        exchangePointProductService.delExchangePointProducts(cn);
        return Result.success();
    }
}
